package com.eu.ebpm.engine.cmd.pvm;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.eu.ebpm.engine.entity.history.HisTaskVariable;
import com.eu.ebpm.engine.express.VariableType;
import com.eu.ebpm.engine.repository.HisTaskVariableRepository;


/**
 * @author 王晓华
 */
public class PvmCommand {
	
	@Autowired
	private HisTaskVariableRepository hisTaskVariableRepository;

	public void insertHisTaskVariable(Long taskId, Map<String, Object> vs) {
		if (vs != null) {
			for (String key : vs.keySet()) {
				/**
				 * @注意：历史任务参数表中：taskId不能是运行任务的id，因为serviceTask没有运行任务，所以必须增加历史任务的taskId
				 */
				HisTaskVariable hisTaskVariable = new HisTaskVariable();
				hisTaskVariable.setTaskId(taskId);
				hisTaskVariable.setName(key);
				Object value = vs.get(key);
				hisTaskVariable.setValue(value);
				hisTaskVariable.setType(VariableType.typeOf(value));
				hisTaskVariableRepository.insert(hisTaskVariable);
			}
		}
	}
	
}